const WebSocket = require("ws");

const client = new WebSocket("ws://129.226.151.230:6657/gemini?auth=6f320577e84b27c9e4a610ec4187316b");

client.on("open", () => {
    client.send(JSON.stringify({
        type: "stream",
        request: true,
        id: "123123123",
        prompt: "你好！"
    }));
    console.log("Client connected!");
})

client.on("message", (message) => {
    if (message.toString().toLowerCase() === "ping") {
        console.log("[Gemini] heartBeatRecved.");
        client.send("Pong");
        return;
    }
    try {
        message = JSON.parse(message.toString());
    } catch(err) {
        console.log(err);
        return;
    }

    console.log(message);
})
client.on("close", () => {
    console.log("Client closed");
    process.exit(0);
})
client.on("error", (err) => {
    console.log(err);
})